package com.example.resaurant_system_layer4.res_sys.controller;


import com.example.resaurant_system_layer4.common.result.ResultUtils;
import com.example.resaurant_system_layer4.res_sys.entity.Board;
import com.example.resaurant_system_layer4.res_sys.service.IBoardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author littlemidi
 * @since 2024-10-24
 */
@RestController
@RequestMapping("/board")
public class BoardController {
    @Autowired
    IBoardService service;

    //写一个getlist获取users表的所有数据
    @GetMapping("/")
    public Object getList(){
        List<Board> list = service.list();
        return ResultUtils.returnDataSuccess(list);
    }

    @GetMapping("/{id}")
    public Object getOne(@PathVariable("id") Integer id){
        Board u = service.getById(id);
        return ResultUtils.returnDataSuccess(u);
    }

    @PostMapping("/")
    public Object add(@RequestBody Board u){
        if (service.save(u)){
            return ResultUtils.returnDataSuccess(u);
        }
        return ResultUtils.returnFail("添加失败");
    }

    @PutMapping("/")
    public Object update(@RequestBody Board u){
        if (service.updateById(u)){
            return ResultUtils.returnDataSuccess(u);
        }
        return ResultUtils.returnFail("修改失败");
    }

    @DeleteMapping("/")
    public Object del(@RequestParam Integer id){
        if (service.removeById(id)){
            return ResultUtils.returnSuccess();
        }
        return ResultUtils.returnFail("删除失败");
    }
}
